<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class CoreDaerah {

    private $mIdKota;
    private $mNamaKota;
    private $mIdKecamatan;
    private $mNamaKecamatan;
    private $mIdKelurahanDesa;
    private $mNamaKelurahanDesa;

    
    public function GetArrayListKecamatan() {
        $mQuery = new DBQueryParse();
        $tResult = array();

        $tSQL = "SELECT id_kecamatan, nama_kecamatan, kota_id FROM app_master_kecamatan WHERE kota_id= \"$this->mIdKota\" ORDER BY nama_kecamatan";
        $tRes = $mQuery->Execute($tSQL);

        if ($tRes->Count() > 0) {
            while($tRes->MoveNext()){
                $tResult[$tRes->id_kecamatan]['nama_kecamatan']= $tRes->nama_kecamatan;
                $tResult[$tRes->id_kecamatan]['kota_id']= $tRes->kota_id;
                //$tRes
            }
            return $tResult;
        } else {
            return false;
        }
    }
    
    public function GetArrayListKelurahanDesa() {
        $mQuery = new DBQueryParse();
        $tResult = array();

        $tSQL = "SELECT id_kelurahan_desa, nama_kelurahan_desa, kecamatan_id FROM app_master_kelurahan_desa WHERE kecamatan_id= \"$this->mIdKecamatan\" ORDER BY nama_kelurahan_desa";
        $tRes = $mQuery->Execute($tSQL); //echo $tSQL;

        if ($tRes->Count() > 0) {
            while($tRes->MoveNext()){
                $tResult[$tRes->id_kelurahan_desa]['nama_kelurahan_desa']= $tRes->nama_kelurahan_desa;
                $tResult[$tRes->id_kelurahan_desa]['kecamatan_id']= $tRes->kecamatan_id;
                //$tRes
            }
            return $tResult;
        } else {
            return false;
        }
    }
    
    
    /* ===== *//* ===== *//* ===== *//* ===== *//* ===== *//* ===== *//* ===== */
    /*                              MUTUATOR                                   */
    /* ===== *//* ===== *//* ===== *//* ===== *//* ===== *//* ===== *//* ===== */
    public function SetKota($pKotaId) {
        $mValidation = new InputValidation();
        $mValidation->SetInput($pKotaId);
        $mValidation->SetPattern(pUnsignedInt);
        $tKota = $mValidation->CheckValidation();

        $mQuery = new DBQueryParse();
        $tSQL = "SELECT nama_kota FROM app_master_kota WHERE id_kota=\"$tKota\" ";
        $tRes = $mQuery->Execute($tSQL);

        if ($tRes->Count() > 0) {
            $tRes->MoveFirst();
            
            $this->mNamaKota = $tRes->nama_kota;
            $this->mIdKota = $tKota;
        }
    }
    
    public function SetKecamatan($pKecamatanId) {
        $mValidation = new InputValidation();
        $mValidation->SetInput($pKecamatanId);
        $mValidation->SetPattern(pKecamatanId);
        $tKecamatan_id = $mValidation->CheckValidation();

        $mQuery = new DBQueryParse();
        $tSQL = "SELECT nama_kecamatan FROM app_master_kecamatan WHERE id_kecamatan=\"$tKecamatan_id\" ";
        $tRes = $mQuery->Execute($tSQL);

        if ($tRes->Count() > 0) {
            $tRes->MoveFirst();
            
            $this->mNamaKecamatan = $tRes->nama_kecamatan;
            $this->mIdKecamatan = $tKecamatan_id;
        }
    }
    
    public function SetKelurahanDesa($pKelurahanDesaId) {
        $mQuery = new DBQueryParse();
        $tSQL = "SELECT nama_kelurahan_desa FROM app_master_kelurahan_desa WHERE id_kelurahan_desa=\"$pKelurahanDesaId\" ";
        $tRes = $mQuery->Execute($tSQL);

        if ($tRes->Count() > 0) {
            $tRes->MoveFirst();
            
            $this->mNamaKelurahanDesa = $tRes->nama_kelurahan_desa;
            $this->mIdKelurahanDesa = $pKelurahanDesaId;
        }
    }
    
    public function GetKota(){
        return $this->mNamaKota;
    }
    
    public function GetKecamatan(){
        return $this->mNamaKecamatan;
    }
    
    public function GetKelurahanDesa(){
        return $this->mNamaKelurahanDesa;
    }

}

?>
